package com.its.web;

import com.its.pojo.User;
import com.its.service.UserService;
import com.its.util.HttpStatusEnum;
import com.its.util.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 朱厚强
 * @since 2024年01月17日
 */
@RestController
@RequestMapping("/user")
@Api(tags = "user-api")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable String id) throws InterruptedException {
        if ("1".equals(id) ){
            int i = 1/0; // 模拟异常
//            Thread.sleep(500);  //模拟休眠时间
        }

       return userService.getByIds(id);
    }
    @GetMapping("/show")
    public String show(HttpServletRequest request){
        String token = request.getHeader("token");
        System.out.println("token = " + token);
        return " token = " + token ;
    }
    @GetMapping("/queryUserAll")
    public String queryUserAll(){
        return "查询所有用户成功" ;
    }
    @GetMapping("/queryUser")
    public String queryUser(){
        return "查询单个用户成功" ;
    }
}
